/*
 * Copyright 2007-2009 Perttu "celeron55" Ahola <celeron55@gmail.com>
 *
 * This file is part of jukumagic.
 *
 * jukumagic is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * jukumagic is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with jukumagic.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef JUKUAPP_H_
#define JUKUAPP_H_

#include <wx/wxprec.h>
#include <wx/cmdline.h>
#include <wx/wx.h>
#include <string>
#include <vector>
#include <map>

#include "jukuframe.h"
#include "jukuobject.h"
#include "project.h"
#include "settings.h"
#include "footprintlibrary.h"
#include "pythonapi.h"

class JukuApp: public wxApp, private JukuObject
{
private:
	std::map< std::string, JukuObject*(*)(TiXmlElement* element) > xml_read_fn_map;
	wxString m_current_file_path;
	
	void ChildChanged(ObjectChangeType type, JukuObject *obj);
	
	/*
		These are changed by OnCmdLineParsed() or similar before OnInit()
	*/
	wxString m_initial_title;
	wxString m_initial_status;

public:
	
	JukuFrame *m_frame;
	Project *m_project;
	FootprintLibrary m_library;
	Settings m_settings;
	PythonApi m_pythonapi;

	JukuApp();
	~JukuApp();
    bool OnInit();
    int OnExit();
    //virtual int OnRun();
    void OnInitCmdLine(wxCmdLineParser& parser);
    bool OnCmdLineParsed(wxCmdLineParser& parser);
    bool NewProject(wxString filepath);
    bool OpenProject(wxString filepath);
    bool SaveProject(wxString filepath);
    bool CloseProject();
	bool RegisterReadXMLFunction(const char *type_name, JukuObject*(*read_xml_function)(TiXmlElement *));
	void InitXMLFunctions();
	JukuObject* ReadXMLElement(TiXmlElement *element);
	/*
		This can be called at any point of execution, not depending on whether
		OnInit has been called or not.
	*/
	void AnytimeExit();
};

DECLARE_APP(JukuApp)

#endif

